(1)首先在current文件夹下新建服务有关的nginx配置文件nginx.conf
upstream news_server { server unix:/tmp/unicorn.news.sock fail_timeout=0; } server { listen 8888; access_log /opt/app/ruby/news/current/log/nginx.access.log; error_log /opt/app/ruby/news/current/log/nginx.error.log; client_max_body_size 4G; keepalive_timeout 5; root /opt/app/ruby/news/current/public; location ^~ /assets/ { gzip on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://news_server; } error_page 500 502 503 504 /500.html; location = /500.html { root /opt/app/ruby/news/current/public; } }
(2)在服务器检查下nginx语法,顺便查看位置
[root@localhost opt]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
查看nginx的配置
vim /etc/nginx/nginx.conf
找到默认conf配置文件放的位置
user nginx; worker_processes 8; 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;
从最后一句话中我们可以得知,所有/etc/nginx/conf.d/下的后缀名为.conf的配置文件都会被include进来,
所以需要做一个软链接,将我们应用部署目录下的nginx配置文件链到这个文件夹下,重启检测下语法 并重启nginx
[root@localhost opt]# ln -s /opt/app/ruby/news/current/config/nginx.conf /etc/nginx/conf.d/new.conf [root@localhost opt]# ll /etc/nginx/conf.d/ 总用量 8 -rw-r--r-- 1 root root 1097 9月 16 2014 default.conf -rw-r--r-- 1 root root 427 9月 16 2014 example_ssl.conf lrwxrwxrwx 1 root root 44 9月 18 10:56 new.conf -> /opt/app/ruby/news/current/config/nginx.conf [root@localhost opt]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@localhost opt]# nginx -s reload [root@localhost opt]# netstat -tlnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:xxxx 0.0.0.0:* LISTEN 8591/nginx: worker tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8591/nginx: worker tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2656/sshd tcp 0 0 0.0.0.0:xxxx 0.0.0.0:* LISTEN 8591/nginx: worker tcp 0 0 0.0.0.0:xxxx 0.0.0.0:* LISTEN 14200/python tcp6 0 0 :::3306 :::* LISTEN 15326/mysqld tcp6 0 0 :::21 :::* LISTEN 5186/vsftpd tcp6 0 0 :::22 :::* LISTEN 2656/sshd