Nginx 安裝使用

shleyZ發表於2019-01-19

nginx基本操作

安裝:

yum install nginx

啟動:

service nginx start

停止:

    
service nginx stop

過載:

    
service nginx reload


部署NGINX:

// $ sudo service httpd stop
$ sudo yum install nginx

檢視是否啟動:


$ ps -ef | grep nginx

啟動:

$ sudo service nginx start
$ sudo service nginx reload



firewall-cmd --zone=public --add-port=80/tcp --permanent
防火牆開啟80埠
firewall-cmd --reload
防火牆過載
yum install iptables-services
systemctl enable iptables
systemctl stop firewalld
systemctl start firewalld

配置/etc/nginx/下的配置檔案:

因為在nginx主配置檔案中引入了conf.d資料夾中的:
include /etc/nginx/conf.d/*.conf;
所以在nginx/conf.d/下面新增qingyun.conf檔案進行配置.

主配置檔案如下:

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/

    user root;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;

    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;

    events {
        worker_connections 1024;
    }

    http {
        log_format  main  `$remote_addr - $remote_user [$time_local] "$request" `
                      `$status $body_bytes_sent "$http_referer" `
                      `"$http_user_agent" "$http_x_forwarded_for"`;

        access_log  /var/log/nginx/access.log  main;

        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;

        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;

        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;

        server {
            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  _;
            root         /usr/share/nginx/html;

          # Load configuration files for the default server block.
          include /etc/nginx/default.d/*.conf;

          location / {
          }

          error_page 404 /404.html;
              location = /40x.html {
          }

          error_page 500 502 503 504 /50x.html;
              location = /50x.html {
              }
          }
      }



  1. 首先主配置檔案,修改使用者組

    user root;

2.然後進行操作:

cd conf.d
touch abcdefg.conf  //新建檔案
vim abcdefg.conf  

修改abcdefg.conf:

server {
        listen       80;
        server_name  **.**.***.**;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/******/******;
            index  index.html index.htm;
        try_files $uri /index.html;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }    

react-router在nginx上的應用,參照:

調整nginx正確服務react-router應用

注意在linux進行解壓檔案時

unrar e build.rar build

這樣會把build.rar裡面所有的檔案都解壓到build資料夾,不保持原有的目錄。

unrar x build.rar build

這樣解壓會保持原有的目錄。

相關文章