Linux云服务-nginx配置篇 秒速五厘米 2024-04-02 03:46 28阅读 0赞 Linux云服务-nginx配置篇 (1)查看nginx进程 > ps aux|grep nginx ![ef7386bdbe424149af47e4afe1705acd.png][] (2)查看nginx端口 > netstat -ntlp ![3dc51f8a8fd74784be2dac2195b31083.png][] (3)开放80端口 > firewall-cmd --zone=public --add-port=80/tcp --permanent 重新加载 > systemctl restart firewalld.service ![0e045b45ac18415cb0f5d1c6e97fea1b.png][] 配置nginx > vim /usr/local/nginx/conf/nginx.conf > > \#user nobody; > worker\_processes 1; > > \#error\_log logs/error.log; > \#error\_log logs/error.log notice; > \#error\_log logs/error.log info; > > \#pid logs/nginx.pid; > > > events \{ > worker\_connections 1024; > \} > > > http \{ > include mime.types; > default\_type application/octet-stream; > > \#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 logs/access.log main; > > sendfile on; > \#tcp\_nopush on; > > \#keepalive\_timeout 0; > keepalive\_timeout 65; > > \#gzip on; > > server \{ > listen 80; > server\_name localhost; > > \#charset koi8-r; > > \#access\_log logs/host.access.log main; > > location / \{ > root /home/yang/dist/; \#前端位置 > try\_files $uri $uri/ /index.html; > index index.html index.htm; > \} > > > location /prod-api/ \{ > proxy\_set\_header Host $http\_host; > proxy\_set\_header X-Real-IP $remote\_addr; > proxy\_set\_header REMOTE-HOST $remote\_addr; > proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for; > proxy\_pass http://localhost:8080/; \#后端地址 > > \} > > \#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; > \} > > \# proxy the PHP scripts to Apache listening on 127.0.0.1:80 > \# > \#location ~ \\.php$ \{ > \# proxy\_pass http://127.0.0.1; > \#\} > > \# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 > \# > \#location ~ \\.php$ \{ > \# root html; > \# fastcgi\_pass 127.0.0.1:9000; > \# fastcgi\_index index.php; > \# fastcgi\_param SCRIPT\_FILENAME /scripts$fastcgi\_script\_name; > \# include fastcgi\_params; > \#\} > > \# deny access to .htaccess files, if Apache's document root > \# concurs with nginx's one > \# > \#location ~ /\\.ht \{ > \# deny all; > \#\} > \} > > > \# another virtual host using mix of IP-, name-, and port-based configuration > \# > \#server \{ > \# listen 8000; > \# listen somename:8080; > \# server\_name somename alias another.alias; > > \# location / \{ > \# root html; > \# index index.html index.htm; > \# \} > \#\} > > > \# HTTPS server > \# > \#server \{ > \# listen 443 ssl; > \# server\_name localhost; > > \# ssl\_certificate cert.pem; > \# ssl\_certificate\_key cert.key; > > \# ssl\_session\_cache shared:SSL:1m; > \# ssl\_session\_timeout 5m; > > \# ssl\_ciphers HIGH:!aNULL:!MD5; > \# ssl\_prefer\_server\_ciphers on; > > \# location / \{ > \# root html; > \# index index.html index.htm; > \# \} > \#\} > > \} 配置完校验配置是否正确 > cd /usr/local/nginx/sbin > ./nginx -t 配置正确 ![1f4ea7442b264febb4dde37d756a319e.png][] 最后一步,在sbin目录下重新启动nginx > ./nginx -s reload ![7b7e071ff80f4f2490952209caf9c806.png][] [ef7386bdbe424149af47e4afe1705acd.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/02/9b3d982e98614e35b290fe63eea2a374.png [3dc51f8a8fd74784be2dac2195b31083.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/02/877d6a727d024a1a918663adfb3b9582.png [0e045b45ac18415cb0f5d1c6e97fea1b.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/02/916798751208473591958b7f3b1b5b6c.png [1f4ea7442b264febb4dde37d756a319e.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/02/810ff0d641b7456b8664363388d53258.png [7b7e071ff80f4f2490952209caf9c806.png]: https://image.dandelioncloud.cn/pgy_files/images/2024/04/02/099b97c4ce2c4a19ab8bf8dd0695aedb.png
还没有评论,来说两句吧...