https://www.linode.com/docs/web-servers/nginx/how-to-configure-nginx http://www.jianshu.com/p/9a6c96ecc8b8
安裝php
CentOS 64 rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm yum install nginx //啓動中止 whereis nginx 找到位置 service nginx start /usr/sbin/nginx -s stop//reload /usr/sbin/nginx -t //測試配置文件 service nginx status//當前狀態 開機自啓動chkconfig nginx on 添加端口號: 永久性添加只須要下面2條命令之一: firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --permanent --add-service=http 從新載入,便可 firewall-cmd --reload 對應的查詢和刪除命令: firewall-cmd --query-port=80/tcp 查看哪些端口打開了firewall-cmd --zone=public --list-ports 查看哪些服務打開了:firewall-cmd --list-services ,查看哪些服務能夠打開firewall-cmd --get-services firewall-cmd --zone=public --remove-port=80/tcp --permanent firewall-cmd --remove-service=http --zone=public --permanent service firewalld //start stop status enable disable restart
原文連接html
1.靜態服務器node
server { listen 80; # 端口號 location / { root /usr/share/nginx/html; # 靜態文件路徑 } }
2.反向代理nginx
server { listen 80; location / { proxy_pass http://192.168.20.1:8080; # 應用服務器HTTP地址 } }
3.負載均衡web
upstream myapp { server 192.168.20.1:8080; # 應用服務器1 server 192.168.20.2:8080; # 應用服務器2 } server { listen 80; location / { proxy_pass http://myapp; } }
4.虛擬主機windows
server { listen 80 default_server; server_name _; return 444; # 過濾其餘域名的請求,返回444狀態碼 } server { listen 80; server_name www.aaa.com; # www.aaa.com域名 location / { proxy_pass http://localhost:8080; # 對應端口號8080 } } server { listen 80; server_name www.bbb.com; # www.bbb.com域名 location / { proxy_pass http://localhost:8081; # 對應端口號8081 } }
5.FastCGIcentos
server { listen 80; location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME /PHP文件路徑$fastcgi_script_name; # PHP文件路徑 fastcgi_pass 127.0.0.1:9000; # PHP-FPM地址和端口號 # 另外一種方式:fastcgi_pass unix:/var/run/php5-fpm.sock; } }
原文連接服務器
例子1:靜態標準服務器app
server { listen 80; server_name localhost; location / { root myhtml; index index.html index.htm; autoindex on; } }
nginx\myhtml負載均衡
....................\.index.html
.....................\blog
...........................\otherfiles
.............................\somepath
............................................\circuit.png
............................................\hi.html
以上是windows下的文件目錄圖。
訪問localhost,會以index.html的內容顯示主頁。
由於打開了autoindex,訪問 localhost/blog,會顯示
例子2:特殊文件結尾的處理
server { listen 80; server_name localhost; location / { root myhtml; index index.html index.htm; autoindex on; } location ~ \.png{ root images; } }
nginx/images
..................pic/circuit.png
..................circuit.png
訪問localhost/circuit.png
localhost/pic/circuit.png
都能顯示該圖片。
例子3:處理location /somepath這樣的URI
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root myhtml; index index.html index.htm; } location /blog/ { root myhtml2; #index hi.html; autoindex on; }
myhtml2結構圖:
nginx\myhtml2
....................\.index.html
.....................\blog
...........................\hi.html
.............................\somepath
............................................\circuit.png
............................................\hi.html
訪問localhost/blog,
localhost/blog/somepath都顯示目錄圖。訪問相似localhost/blog/somepath/circuit.png顯示具體圖片。
若是index hi.html打開
目錄下有hi.html的話,顯示對應html,沒有則會103 Forbidden。