nginx启动和停止
linux中启动
sudo nginx
启动报错
初次启动时,会报如下错误
/usr/local/nginx/nginx8011/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
执行下列语句,就OK 了
export LD_LIBRARY_PATH=/home/whuang/software/nginx/pcre-8.30/.libs/:$LD_LIBRARY_PATH
指定配置文件启动
sudo nginx -c /etc/nginx/nginx.conf
使用-c 来指定配置文件
重新启动
sudo nginx restart
测试配置文件
/usr/local/nginx/nginx8011/sbin/nginx -t
重新加载配置文件
nginx.exe -s reload
停止nginx
/usr/local/nginx/nginx8011/sbin/nginx -s stop
使nginx支持跨域
server {
listen 80;
location /chanjet {
add_header Access-Control-Allow-Origin *;
root /opt/yunyingyong/mainsite/mainsite/src/web_js/www;
}
location / {
proxy_pass http://172.18.22.170:8080;
#proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
为什么在/etc/nginx/nginx.conf 中配置的不起作用?
因为/etc/nginx/sites-enabled/default
解决方法:
编辑/etc/nginx/nginx.conf ,注释掉
include /etc/nginx/sites-enabled/*;