日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux(centos7)安装nginx并配置代理

發布時間:2024/4/15 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux(centos7)安装nginx并配置代理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

安裝并啟動nignx

通過yum進行安裝

[root@server ~]# yum install nginx [root@server ~]# service nginx start

然后進入瀏覽器,訪問服務器ip,如果看到

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

恭喜你,你成功了!

如果不成功,檢查防火墻是否放過了80端口,放開80端口即可。

配置文件

當你執行nginx -t得時候,nginx會去測試你得配置文件得語法,并告訴你配置文件是否寫得正確,同時也告訴了你配置文件得路徑:

# nginx -t nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

反向代理

編輯nginx.conf文件

vim nginx.conf

在文件中添加或修改:

server {listen 80; //監聽80端口server_name www.xxx.xxx; //請求地址location / {proxy_pass http://localhost:8081; //代理的地址和端口proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} }

這樣設置后,凡是www.xxx.xxx這個域名的請求都會代理到8081端口上。

可以在conf文件中有多個server,這樣就能實現不同的二級域名代理到不同的端口上。

重啟nginx

[root@server ~]# service nginx restart

如果重啟出錯,如下:
重啟nginx出錯

Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.

終端中輸入nginx -t命令就可以查看具體問題了。

日志

nginx日志地址為/var/log/nginx/目錄下

如果想下載日志到本地查看,可以:

scp root@[服務端ip]:/var/log/nginx/xxx.xxx [本地目錄,如:~/Downloads/]

無法訪問

配置代理后依然訪問不了

這里指的是ping不通,報錯Unknown host的情況

這是因為代理的域名沒有加入DNS解析,在阿里云中添加二級域名DNS解析即可

添加完需要等一段時間才行

總結

以上是生活随笔為你收集整理的Linux(centos7)安装nginx并配置代理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。