nginx配置一下不仅可以做静态服务器,还可以转发请求到服务端本地的端口服务。以前装wordpress这些程序我们会惯例一样地去安装apache,但是如果你装了nginx,就不再需要安装apache了。下面是一个我自己用的配置,我的服务器是centos 7。
这些说明文字有可能有助于你对下面这个配置的理解:
- 我有两个域名,分别是orzzone.com和yxeye.com;
- orzzone.com使用的服务是由一个php程序wordpress提供的;
- yxeye.com使用的服务是由一个node服务提供的,node服务使用的端口号为18080。
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; server { listen 80; server_name www.yxeye.com; location / { #.... proxy_pass http://localhost:18080; } ##### other directive } server { listen 80; server_name www.orzzone.com; root /var/www/html/orzzone.com/public_html/wordpress; index index.php index.html; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } ##### other directive } }