1. 安装
2. 增加代理配置
1 2
| cd /etc/nginx/sites-available vim your_site_name
|
普通http配置参考:
1 2 3 4 5 6 7 8 9 10 11 12 13
| # http server server { listen 80; server_name your.site.name.cn; # ssl on; access_log /var/log/nginx/syour_site_name.access.log; error_log /var/log/nginx/your_site_name.error.log; location / { proxy_pass http://127.0.0.1:8011; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward_For $proxy_add_x_forwarded_for; }
|
安全https配置参考:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| # HTTPS server server { listen 443; listen [::]:443 ipv6only=on; server_name your.site.name.cn; ssl on; access_log /var/log/nginx/your_site_name.access.log; error_log /var/log/nginx/your_site_name.error.log; ssl_certificate /path/to/your/https/cert/your_site_name.pem; ssl_certificate_key /path/to/your/https/cert/your_site_name.key; ssl_session_timeout 5m;
location / { proxy_pass http://127.0.0.1:8012; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward_For $proxy_add_x_forwarded_for; } }
|
将文件链接至sites-enabled目录下。
1
| ln -s /etc/nginx/sites-available/your_site_name /etc/nginx/sites-enabled/your_site_name
|
*这是因为sites-available目录下存放的只是备选配置,sites-enabled目录下才是真正有效的代理设置。
3. Nginx配置
1
| vim /etc/nginx/nginx.conf
|
修改下前几行内容:
1 2 3 4 5 6 7 8 9
| user www-data; worker_processes 4; # worker数 worker_rlimit_nofile 60000; pid /run/nginx.pid;
events { worker_connections 65535; # 最大同时连接数 multi_accept on; # 开启接受同时连接选项 }
|
4. 重载配置
1
| /usr/sbin/nginx -s reload
|
这一步做完Nginx已经可以正常工作了。
5. 常用命令
5.1 启动
5.2 停止
5.3 验证配置文件是否正确