Linux下安装nginx网站服务-实例服务器系统版本为centos7.6

哈喽,大家好!我是C&JJ,感谢观看,最近刚开始写,打算先写一些简单的服务搭建,后期的话分享些架构与集群。

ok步入今天的正题,今天在centos7(Linux)下安装一个Nginx网站服务。

  先简单介绍下Nginx,其实在centos7下搭建一个nginx是非常简单的,但是配合集群的话配置起来就比较麻烦了,
nginx可以用来做反向代理、负载均衡和HTTP服务器,那今天呢我们只搭建网站,后面再配合发一些集群。ok 开始!

先介绍下我当前服务器的环境,云服务器、系统版本是centos7的、有公网权限。
1、首先我们需要准备nginx的包。(我这边是问其他朋友要的后续会传到CSDN免费分享给大家)

[root@VM-16-3-centos ~]# ll
total 4438948
-rw-r--r-- 1 root root 4521459712 Aug 10 20:57 CentOS-7-x86_64-DVD-1708.iso
-rw-r--r-- 1 root root     980831 Aug 19 11:10 nginx-1.12.0.tar.gz       ##Nginx包
drwxr-xr-x 7 root root       4096 Aug 18 16:30 python36
-rw-r--r-- 1 root root   23010188 Dec 24  2018 Python-3.6.8.tgz.1
-rw-r--r-- 1 root root      18479 Aug 18 11:46 wget-log
[root@VM-16-3-centos ~]# 

2、用yum来安装nginx的依赖包。

[root@VM-16-3-centos ~]# yum -y install pcre-devel zlib-devel openssl-devel &>/dev/null 
可以看到上边我指定了不管yum -y install安装这条命令输出的信息都全部丢到无底洞里去。
/dev/null         ## 是unix/linux里的无底洞。

3、解压nginx包。

[root@VM-16-3-centos ~]# tar zxf nginx-1.12.0.tar.gz -C /usr/src/
[root@VM-16-3-centos ~]# cd /usr/src/
[root@VM-16-3-centos src]# ll
total 12
drwxr-xr-x. 2 root root 4096 Apr 11  2018 debug
drwxr-xr-x. 3 root root 4096 Apr 22 16:08 kernels
drwxr-xr-x  8 1001 1001 4096 Apr 12  2017 nginx-1.12.0
上面我指定了解压的路径/usr/src/。

4、进入解压后的nginx目录里进行配置、编译和安装。

[root@VM-16-3-centos nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module
checking for OS
 + Linux 3.10.0-1062.18.1.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... not found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_RECVDSTADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for kqueue AIO support ... not found
checking for Linux AIO support ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

[root@VM-16-3-centos nginx-1.12.0]# make && make install   ##我这里直接编译和安装一起执行了。
[root@VM-16-3-centos nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin/   ##制作软连接,优化下执行路径。

5、启动nginx,再此次演示的时候出现了一个我第一次遇到的报错,于是我百度了下,少创建了个用户和组,之前安装nginx的时候没有遇到过这个,有点奇怪。

[root@VM-16-3-centos conf]# nginx       ##启动命令
nginx: [emerg] getpwnam("www") failed      ##启动报错;启动失败,需要我们执行下面两条命令,再次启动就ok了。
[root@VM-16-3-centos conf]# /usr/sbin/groupadd -f www
[root@VM-16-3-centos conf]# /usr/sbin/useradd -g www www
[root@VM-16-3-centos conf]# nginx
[root@VM-16-3-centos conf]# ps -ef|grep nginx
root     18351 18248  0 11:57 pts/1    00:00:00 vi nginx.conf
root     18724     1  0 12:00 ?        00:00:00 nginx: master process nginx
www      18725 18724  0 12:00 ?        00:00:00 nginx: worker process
root     18753 18248  0 12:00 pts/1    00:00:00 grep --color=auto nginx

6、访问页面进行验证。(我这里直接把默认的页面内容给改了,加了中文编码,看下面具体操作)

[root@VM-16-3-centos ~]# vi /usr/local/nginx/html/index.html    ##进入以后把里面的全部删掉,然后输入下面的。(或着自己输入自己想的字)
        ##指定utf-8.
哈喽,你好,我是C&JJ。


:wq!
[root@VM-16-3-centos ~]# nginx -s reload               ##重启nginx。

然后我们去浏览器输入IP地址进行访问。
Linux下安装nginx网站服务-实例服务器系统版本为centos7.6_第1张图片
ok,本次nginx安装到此结束。

你可能感兴趣的:(学习,nginx,linux,centos,运维)