1. 首页
  2. 技术知识

Nginx配置使用详解

配置步骤:

1、配置nginx的方法:首先要打开“/etc/nginx/conf.d/”文件夹;

2、然后创建配置文件;接着在“/etc/nginx/nginx.conf”文件中修改配置项;

3、最后重新启动nginx即可

Nginx是一款轻量级的Web 服务器/反向X服务器及电子邮件(IMAP/POP3)X服务器

Nginx (engine x) 也是一个高性能的HTTP和反向X服务,也是一个IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的 (推荐学习:nginX程)


前后端nginx配置

1.打开 /etc/nginx/conf.d/文件夹,创建配置文件xxx.conf,内容如下:

  1.     server {
  2.     listen 80;
  3.     server_name **.106.2**.175;
  4.     location / {
  5.             root   /public/APP/dist;
  6.             index  index.php index.html index.htm;
  7.     }
  8.     location /sell {
  9.         proxy_set_header   X-Real-IP $remote_addr;
  10.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  11.         proxy_set_header   Host      $http_host;
  12.         proxy_set_header X-NginX-Proxy true;
  13.         proxy_pass         http://127.0.0.1:8080;
  14.         proxy_redirect off;
  15.     }}

复制代码 2.在 /etc/nginx/nginx.conf文件中有一行就是把刚刚配置的引进总的nginx配置中

  1.     include /etc/nginx/conf.d/*.conf;…

复制代码 3.配置完成后重新启动nginx

  1. nginx -t                         # 查看nginx状态
  2. nginx -s reload            # 重新载入配置文件
  3. nginx -s reopen           # 重启 Nginx
  4. nginx -s stop               # 停止 Nginx

复制代码 4.配置https

  1. server {
  2.         listen 443;
  3.         server_name xx.name.com;
  4.         ssl on;
  5.         index index.html index.htm;
  6.         ssl_certificate   cert/215079423330181.cert;
  7.         ssl_certificate_key  cert/215079423330181.key;
  8.         ssl_session_timeout 5m;
  9.         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  10.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  11.         ssl_prefer_server_ciphers on;
  12.         location / {
  13.            root   /public/app/dist;
  14.            index  index.php index.html index.htm;
  15.         }
  16.         location /sell {
  17.             proxy_set_header   X-Real-IP $remote_addr;
  18.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  19.             proxy_set_header   Host      $http_host;
  20.             proxy_set_header X-NginX-Proxy true;
  21.             proxy_pass         http://127.0.0.1:8080;
  22.             proxy_redirect off;
  23.         }
  24.    }

复制代码 5.nginx.conf 默认文件

  1. # For more information on configuration, see:
  2. #   * Official English Documentation: http://nginx.org/en/docs/
  3. #   * Official Russian Documentation: http://nginx.org/ru/docs/
  4. user nginx;
  5. worker_processes auto;
  6. error_log /var/log/nginx/error.log;
  7. pid /run/nginx.pid;
  8. # Load dynamic modules. See /usr/share/nginx/README.dynamic.
  9. include /usr/share/nginx/modules/*.conf;
  10. events {
  11.     worker_connections 1024;
  12. }
  13. http {
  14.     log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
  15.                       ‘$status $body_bytes_sent “$http_referer” ‘
  16.                       ‘”$http_user_agent” “$http_x_forwarded_for”‘;
  17.     access_log  /var/log/nginx/access.log  main;
  18.     sendfile            on;
  19.     tcp_nopush          on;
  20.     tcp_nodelay         on;
  21.     keepalive_timeout   65;
  22.     types_hash_max_size 2048;
  23.     gzip on;
  24.     gzip_static on;
  25.     gzip_min_length 1024;
  26.     gzip_buffers 4 16k;
  27.     gzip_comp_level 2;
  28.     gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript   application/x-httpd-php application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
  29.     gzip_vary off;
  30.     gzip_disable “MSIE [1-6]\.”;
  31.     include             /etc/nginx/mime.types;
  32.     default_type        application/octet-stream;
  33.     # Load modular configuration files from the /etc/nginx/conf.d directory.
  34.     # See http://nginx.org/en/docs/ngx_core_module.html#include
  35.     # for more information.
  36.     include /etc/nginx/conf.d/*.conf;
  37.     server {
  38.         listen       80 default_server;
  39.         listen       [::]:80 default_server;
  40.         server_name  _;
  41.         root         /usr/share/nginx/html;
  42.         # Load configuration files for the default server block.
  43.         include /etc/nginx/default.d/*.conf;
  44.         location / {
  45.         }
  46.         error_page 404 /404.html;
  47.             location = /40x.html {
  48.         }
  49.         error_page 500 502 503 504 /50x.html;
  50.             location = /50x.html {
  51.         }
  52.     }
  53.     server {
  54.          listen 443;
  55.          server_name mp.hanxìng.store;
  56.          ssl on;
  57.          index index.html index.htm;
  58.          ssl_certificate   cert/cert_mp.hanxìng.store.crt;
  59.          ssl_certificate_key  cert/cert_mp.hanxìng.store.key;
  60.          ssl_session_timeout 5m;
  61.          ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  62.          ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  63.          ssl_prefer_server_ciphers on;
  64.          location / {
  65.             root   /public/sell/app/dist;
  66.             index  index.php index.html index.htm;
  67.          }
  68.          location /sell {
  69.              proxy_set_header   X-Real-IP $remote_addr;
  70.              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  71.              proxy_set_header   Host      $http_host;
  72.              proxy_set_header X-NginX-Proxy true;
  73.              proxy_pass         http://127.0.0.1:8080;
  74.              proxy_redirect off;
  75.          }
  76.          error_page 404 /404.html;
  77.               location = /40x.html {
  78.          }
  79.          error_page 500 502 503 504 /50x.html;
  80.             location = /50x.html {
  81.          }
  82.     }
  83. }

复制代码 以上就是nginx怎么配置的详细内容!

到此这篇关于Nginx配置使用的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持软件技术网。

原创文章,作者:starterknow,如若转载,请注明出处:https://www.starterknow.com/109115.html

联系我们