mac: php nginx error: file not found

启动方式:
sudo nginx
sudo nginx -s reload
sudo php-fpm
打开浏览器 localhost:8080 , 页面显示“File not found 错误 ”

解决方法:

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

include fastcgi_params;

}

 

方法1: fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

   改成 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  [没效果]

  改成 fastcgi_param SCRIPT_FILENAME /Users/saiwei/Sites/$fastcgi_script_name;  [有效果]

 

参考:

1) http://www.saitjr.com/php/mac-nginx-environment-configuration.html [ 详细]

2)

nginx : 处理跨域 问题

1.

 

add_header Access-Control-Allow-Origin *;
  add_header Access-Control-Allow-Headers X-Requested-With;
  add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
这样就可以实现GET,POST,OPTIONS的跨域请求的支持

django uWSGI and Nginx

http://andrew-liu.gitbooks.io/django-blog/content/xiang_mu_yu_app.html

-------------------------------------------
问:How to stop uwsgi
答: sudo killall -s INT /usr/local/bin/uwsgi
参考:http://serverfault.com/questions/565903/how-to-stop-uwsgi-when-no-pidfile-in-config
-------------------------------------------
问:很多人推荐俺gunicorn 【TODO】
-------------------------------------------
问:更新代码后,及时生效 【TODO】
答:
参考:https://www.v2ex.com/t/182882
-------------------------------------------
问:后台运行
答:在尾部加上&(and)字符表示后台运行
uwsgi –ini my_blog_uwsgi.ini &
参考:http://www.xiaomastack.com/2014/09/12/uwsgi-django-nginx/
-------------------------------------------
问:
答:CONT 18 继续(与STOP相反, fg/bg命令)
STOP 19 暂停(同 Ctrl + Z)
-------------------------------------------
问:connect() to unix:///home/chenwei/workspace/PycharmProjects/helloworld/mysite.sock failed (13: Permission denied)
答:uwsgi –socket mysite.sock –wsgi-file test.py –chmod-socket=666
注: 666 测试成功,  664还是失败
-------------------------------------------
问:官方文档
答:http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html 【重要】
-------------------------------------------
问: Server Error (500)
答:参考: http://www.cnblogs.com/xiami303/p/3341313.html

uwsgi: unrecognized option ‘–wsgi-file’

1. uwsgi –http :8000 –wsgi-file test.py
error: uwsgi: unrecognized option ‘–wsgi-file’
原因:uwsgi 版本太旧造成的。
解决方法:
最好通过python pip安装uwsgi.

$sudo apt-get install python-dev
$sudo apt-get install python-pip
$sudo pip install pip –upgrade
$sudo apt-get install libpcre3 libpcre3-dev
$sudo apt-get install zlib1g-dev
$sudo apt-get install nginx-full
如果安装版本错误,先卸载:

$pip uninstall uwsgi
$sudo apt-get remove uwsgi
python 版本最好是python 2.7.*
pip的版本应该是最新版本。
查看pip 版本:

$pip –version
pip 6.0.7 from /usr/local/lib/python2.7/dist-packages (python 2.7)
接下来安装uwsgi。

$sudo pip install uwsgi

参考:http://segmentfault.com/q/1010000002523354

nginx : 显示目录

1. 在浏览器上输入 saiwei.info/aa , 页面显示403 错误,
可是我有在/aa下放置了文件?

2. 更新配置文件

location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}

参考: https://www.huzs.net/?p=688

nginx location [TODO]

1. 查看二级域名是否配置好了

http://www.oschina.net/question/577286_89527
参考:
https://blog.coding.net/blog/tips-in-configuring-Nginx-location
http://blog.sina.com.cn/s/blog_97688f8e0100zws5.html
http://my.oschina.net/comguo/blog/114198

nginx + tornado + Supervisord

1. 编辑进程配置文件

2. 更新状态,出现错误

$ supervisorctl update

error: , [Errno 111] Connection refused: file: /usr/lib/python2.7/socket.py line: 571

解决: 参考:http://stackoverflow.com/questions/18859063/supervisor-socket-error-issue
sudo supervisord -c /etc/supervisor/supervisord.conf
sudo supervisorctl -c /etc/supervisor/supervisord.conf

3. 出现另一个错误
supervisor> update
supervisor> status
tornadoes:tornado-8888 FATAL Exited too quickly (process log may have details)

解决: 
4.

参考: http://gracece.com/2014/03/Tornado-supervisor+nginx/   【详细】

https://serholiu.com/tornado-nginx-supervisord

http://blog.thisisfeifan.com/2012/06/deploy-tornado-application.html

http://mirrors.segmentfault.com/itt2zh/ch8.html

nginx 端口转发

1. nginx 端口转发

upstream tornadoes {
server 127.0.0.1:8888;
}

server {
listen 80;
server_name saiwei.info www.saiwei.info;

location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://tornadoes;
}
}

2.  端口转发后,可以屏蔽不必要的端口号

 

 

参考: http://mirrors.segmentfault.com/itt2zh/ch8.html  【重要】

https://serholiu.com/tornado-nginx-supervisord

http://www.qmailer.net/archives/165.html

 

nginx 多域名

1.  根据 server_name ,区别开

2.

server {
listen 80;
root /var/www/wordpress;
index index.php index.html index.htm;

server_name saiwei.me www.saiwei.me;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

 

server {
listen 80;
server_name saiwei.info www.saiwei.info;
root /var/www/test;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
}

 

 

 

 

参考:http://xiugq.blog.51cto.com/813544/693448

http://www.cnblogs.com/buffer/archive/2011/08/17/2143514.html

http://onlyzq.blog.51cto.com/1228/535279

nginx php 404 , 502

1.  nginx 上部署wordpress  ,参考链接(https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04)

2.

配置文件:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.php index.html index.htm;

        server_name your_domain.com;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

3. 根据参考文件的文章,我自己试了下,写了个最简单的php demo,一直出现404错误界面
Selection_052

4. 解决:是这句【fastcgi_pass unix:/var/run/php5-fpm.sock;】没起到作用,
   改成 【fastcgi_pass   127.0.0.1:9000;】 就ok了

5. 现在的配置
  
 location ~ \.php$ {
  try_files $uri =404;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_index index.php;
  include fastcgi_params;
  }