Nginx修改默認80端口(解決跟Tomcat的端口沖突)
公司的服務器上面有java的環境,現在需求是在部署一個php的環境(lnmp),也沒有這么弄過,通過百度,搜索了一下相關的資料。不要擔心裝完php環境會影響java的環境,這是兩個不同的環境,不會受到印象。只要注意一下幾點沒問題了:
1,Nginx跟Tomcat是屬于兩個服務器,但是都會用到80端口。這樣的問題就是要么就Tomcat修改默認端口。要么就Nginx修改。那Nginx是后來的,只好Nginx修改了。2,在使用yum一鍵安裝lnmp的時候有“mysql”,“php”,“Nginx”等,顧名思義,我們要修改這個安裝信息。因為都是mysql數據庫可以公用一個即可。根據自己的需求來進行配置yum命令。解決方案一、安裝lnmp環境1,復制到xshell里面執行即可。
[root@iZm5e8nyz28v9zr7lhb7moZ install]# wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1 --php_option 7 --phpcache_option 1 --phpmyadmin --mphp_ver 56 --pureftpd --memcached --iptables --reboot2,這個時候PHP很霸道。果斷的把80的端口給搶過來了。我同事用ip訪問他的項目的時候,他說報錯了。我一看下面是404,瀏覽器提示Nginx。我恍然大悟,在Nginx服務器上面沒有部署過這個項目,路徑找不到。那么我需要把80端口還給Tomcat,所以根據以二的步驟,修改Nginx默認的80端口
PS:80端口作為http協議的默認端口,在輸入網站的時候其實瀏覽器(非IE)已經幫忙輸入協議了。所以這樣一來,如果輸入http://baidu.com,其實就等于訪問http://baidu.com:80。二、更改Nginx訪問的80端口1,打開:vim /usr/local/nginx/conf/nginx.conf
[root@iZ28qtbhs9vZ ~]# vim /usr/local/nginx/conf/nginx.conf2,找到service部分,其他的都不需要管。修改“listen 8080(可以隨便寫,建議不要占用系統端口)”,“server_name 你的公網ip”,以下為修改后的:
server { listen 8080; server_name 你的公網ip; access_log /data/wwwlogs/access_nginx.log combined; root /data/wwwroot/default; index index.html index.htm index.php; #error_page 404 /404.html; #error_page 502 /502.html; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }修改前:
server { listen 80; server_name _; access_log /data/wwwlogs/access_nginx.log combined; root /data/wwwroot/default; index index.html index.htm index.php; #error_page 404 /404.html; #error_page 502 /502.html; location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }三,關閉防火墻1,centos版本不同,關閉的方式不同。我的版本是6.9。service iptables stop
[root@iZm5e8nyz28v9zr7lhb7moZ install]# service iptables stopiptables: Setting chains to policy ACCEPT: filter [ OK ]iptables: Flushing firewall rules: [ OK ]iptables: Unloading modules: [ OK ][root@iZm5e8nyz28v9zr7lhb7moZ install]# 四,重啟Nginx服務&重載Nginx配置文件1,執行命令:/etc/init.d/nginx restart
[root@iZm5e8nyz28v9zr7lhb7moZ install]# service iptables stopiptables: Setting chains to policy ACCEPT: filter [ OK ]iptables: Flushing firewall rules: [ OK ]iptables: Unloading modules: [ OK ][root@iZm5e8nyz28v9zr7lhb7moZ install]#2,執行:/usr/local/nginx/sbin/nginx -s reload
[root@iZ28qtbhs9vZ ~]# /usr/local/nginx/sbin/nginx -s reload[root@iZ28qtbhs9vZ ~]#我們去訪問一下吧
到此這篇關于Nginx修改默認80端口(解決跟Tomcat的端口沖突)的文章就介紹到這了,更多相關Nginx修改默認80端口內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
