Nginx反向代理實現ipv4網站能夠經過ipv6訪問

一、修改hosts文件,添加域名和本機Ip綁定,改完後重啓網絡服務html

sudo vim /etc/hostsnode

 1 127.0.0.1 localhost www.web.com  2 127.0.1.1 ChenXin  3 
 4 # The following lines are desirable for IPv6 capable hosts  5 ::1     ip6-localhost ip6-loopback www.web.com  6 fe00::0 ip6-localnet  7 ff00::0 ip6-mcastprefix  8 ff02::1 ip6-allnodes  9 ff02::2 ip6-allrouter 10 0.0.0.0 account.jetbrains.com
/etc/hosts

sudo /etc/init.d/networking restartnginx

二、搭建webapp,這裏使用uWSGI的接口搭建的簡單的web

1 def application(environ, start_response): 2     status = '200 OK'
3     output = 'Hello World!wocaocao'
4  
5     response_headers = [('Content-type', 'text/plain'), 6                         ('Content-Length', str(len(output)))] 7  start_response(status, response_headers) 8  
9     return [output]
test.py

三、配置HTTP服務器,本次使用uWSGI,並打開服務vim

1 [uwsgi] 2 http=127.0.0.1:3031
3 wsgi-file=test.py 4 master=true
5 processes=1
6 threads=2
7 stats=127.0.0.1:9191
uwsgi.ini

sudo uwsgi uwsgi.ini服務器

四、配置Nginx反向代理,並重載nginx配置,重啓nginx服務網絡

vim /etc/nginx/conf.d/www.web1.com.confapp

 1 upstream test.com {  2   server 127.0.0.1:3031;  3 }  4 
 5 
 6 server {  7     listen [::]:80;  8  server_name www.web1.com;  9     access_log /var/log/nginx/www.web1.com_access.log; 10     error_log /var/log/nginx/www.web1.com_error.log; 11     location / { 12  proxy_set_header Host $host:$server_port; 13         proxy_set_header X-Real-IP $remote_addr; 14         proxy_set_header REMOTE-HOST $remote_addr; 15         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 16             proxy_pass http://test.com;
17  } 18 
19 }
www.web1.com.conf

sudo nginx -s reloadwebapp

sudo service nginx restart

ide

五、驗證是否正常的命令

netstat -tulpn #查看監聽端口

sudo nginx -t #查看nginx配置文件是否正確

ps -ef | grep nginx #查看nginx進程

 

參考文章:https://www.cnblogs.com/Erick-L/p/7066455.html

相關文章
相關標籤/搜索