nginx部署(普通用戶)

1. Install Nginx software prerequisites :
$ sudo yum install pcre pcre-devel openssl-devel perl gcc make -y

  

2. Download Nginx from official website and extract it :
$ wget http://nginx.org/download/nginx-1.6.2.tar.gz
$ tar xzvf nginx-1.6.2.tar.gz
 
 
3. 用戶權限設置 chown -R group:user
# chown -R youaijj:youaijj /home/youaijj
 
 
4. make owner directory(在youaijj用戶下執行)
配置文件:
$ mkdir /home/youaijj/etc
執行文件:
$ mkdir /home/youaijj/usr
日誌等:
$ mkdir /home/youaijj/var

  

5. Go to the extracted directory and start Compiling and install Nginx :
$ cd nginx-1.6.2
$ ./configure --prefix=/home/youaijj/etc/nginx --sbin-path=/home/youaijj/usr/sbin/nginx --conf-path=/home/youaijj/etc/nginx/nginx.conf --error-log-path=/home/youaijj/var/log/nginx/error.log --http-log-path=/home/youaijj/var/log/nginx/access.log --pid-path=/home/youaijj/var/run/nginx.pid --lock-path=/home/youaijj/var/run/nginx.lock --http-client-body-temp-path=/home/youaijj/var/cache/nginx/client_temp --http-proxy-temp-path=/home/youaijj/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/home/youaijj/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/home/youaijj/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/home/youaijj/var/cache/nginx/scgi_temp --user=youaijj --group=youaijj--with-http_ssl_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
「--」 不要換行。查看其餘選項:$ ./configure --help
configure的另外方式,換行使用「\」
$ ./configure \
--prefix=/home/youaijj/etc/nginx \
--sbin-path=/home/youaijj/usr/sbin/nginx \
--conf-path=/home/youaijj/etc/nginx/nginx.conf \
--error-log-path=/home/youaijj/var/log/nginx/error.log --http-log-path=/home/youaijj/var/log/nginx/access.log \
...
...
 
 
6. Still in the current, nginx-1.x.x directory, issue the installation command as below :
$ make && make install
 
編譯以後文件內容:
/home/youaijj/etc
 
 
/home/youaijj/usr
 
 
/home/youaijj/var
 
Ps:var下沒有cache目錄,以後須要手動建立
 
 
7. Change server port
由於 普通用戶只能用1024以上的端口,1024之內的端口只能由root用戶使用,所以須要將nginx.conf文件中的80端口改成1024以上,這裏改成了8031.
...
# another virtual host using mix of IP-, name-, and port-based configuration
#
 server {
  listen 8031;
  server_name cjj.test.dev;
  access_log /home/youaijj/var/log/nginx/access.test.log;
 
  location / {
   root html;
   index index.html index.htm;
  }
 }
...
 
 
8. Start Server :
$ cd /home/youaijj/usr/sbin
$ ./nginx
若是出現以下問題:
nginx: [emerg] mkdir() "/home/youaijj/var/cache/nginx/client_temp" failed (2: No such file or directory)
手動建立文件夾,而後從新啓動nginx服務便可。
 
 
9. Result test
[youaijj@youai ~]$ curl localhost:8031
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[youaijj@youai ~]$
 
或者經過瀏覽器訪問 「服務器ip:8031:
 
附:
I. 經過瀏覽器訪問注意檢查是否開放服務器防火牆。Centos7再也不使用iptables,而是使用firewall
    [root@youai nginx]# firewall-cmd --list-ports
    [root@youai nginx]# systemctl status firewalld
    [root@youai nginx]# systemctl start firewalld
    [root@youai nginx]# firewall-cmd --zone=public --add-port=8031/tcp --permanen
重啓防火牆: [root@youai nginx]# systemctl restart firewalld.service
查看狀態: [root@youai nginx]# firewall-cmd --list-ports
 
II. Register Nginx service into systemd as a service by create the file named nginx.service
若是不想每次手動啓動,也能夠將服務註冊到server中,使用systemctl的方式來控制。
相關文章
相關標籤/搜索