Advertisement
Guest User

Untitled

a guest
Apr 20th, 2016
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.74 KB | None | 0 0
  1. Great tutorial. However I experienced problems with php files, for I received a 404 error everytime I tried to access my phpinfo.php file.
  2.  
  3. The root directory is /usr/share/nginx/html, BUT don't be fooled for having declared the index.php in the index line. That root directory is for static content. I spent like 2 hours literally going crazy because when you see a 404 error you might think Nginx is getting the root directory from another one... but in my case I edited the index.html and it got affected, so Nginx was indeed targeting that root directory.
  4.  
  5. Checking the error log file I see that for php files (I still don't know why)
  6.  
  7. What I did, according to my personal needs, was use the same root for all. I just stated it once at the server level and it'll be inherited by all the locations.
  8.  
  9. Here's my default.conf file:
  10.  
  11. server {
  12. listen 80;
  13. server_name www.alemany.me;
  14.  
  15. #charset koi8-r;
  16. access_log /var/log/nginx/alemany.access.log main;
  17. error_log /var/log/nginx/alemany.error.log;
  18.  
  19. root /usr/share/nginx/html;
  20. index index.php index.html index.htm;
  21.  
  22. error_page 404 /404.html;
  23. error_page 500 502 503 504 /50x.html;
  24. location = /50x.html {
  25. root /usr/share/nginx/html;
  26. }
  27.  
  28. location ~ \.php$ {
  29. try_files $uri =404;
  30. include fastcgi_params;
  31. fastcgi_pass unix:/var/run/php-fpm.sock;
  32. fastcgi_index index.php;
  33. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  34. }
  35. }
  36.  
  37. I'm not being redundant here. I might be jumping a couple of things here.
  38.  
  39. Anyway, this is how I worked around this and it's up and running right now.
  40.  
  41. Best regards.
  42. HeartedHeart
  43. 0
  44.  
  45. damijanc
  46. damijanc March 18, 2015
  47.  
  48. Did you check file access permissions. You need read permissions. This is typical error.
  49.  
  50. HeartedHeart
  51. 0
  52.  
  53. alainalemany
  54. alainalemany March 18, 2015
  55.  
  56. I don't think that was the problem. Everytime I tried to access my index.php and got the 404 error, I checked in the logs and by unknown reasons Nginx was looking for the php file in /etc/nginx/html/index.php as you can see below:
  57.  
  58. 2015/03/18 09:37:13 [error] 13192#0: *1 FastCGI sent in stderr: "Unable to open primary script: /etc/nginx/html/index.php (No such file or directory)" while reading response header from upstream, client: 200.55.154.30, server: www.alemany.me, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.alemany.me"
  59.  
  60. I worked around this as I mention previously. If there's a more orthodoxe way, please share it with me.
  61. HeartedHeart
  62. 0
  63.  
  64. damijanc
  65. damijanc March 18, 2015
  66.  
  67. One more thing.
  68.  
  69. you root is pointing to
  70.  
  71. root /usr/share/nginx/html
  72.  
  73. You should change this if you want it to point somewhere else.
  74.  
  75. HeartedHeart
  76. 0
  77.  
  78. akef
  79. akef March 23, 2015
  80.  
  81. work foot
  82. thank you
  83. HeartedHeart
  84. 0
  85.  
  86. sthiina
  87. sthiina April 22, 2015
  88.  
  89. sudo vi /etc/php-fpm.d/www.conf
  90. im not having above path. pleae help.
  91. HeartedHeart
  92. 0
  93.  
  94. dmgap
  95. dmgap July 3, 2015
  96.  
  97. Maybe you do not install php-fpm yet?Or you can find it in whole etc path like:
  98. sudo find /etc -name "www.conf"
  99.  
  100. HeartedHeart
  101. 0
  102.  
  103. saw
  104. saw August 30, 2015
  105.  
  106. Hi, I got some issues start from step four: Configure Nginx to Process PHP Pages
  107.  
  108. After I typed this $ sudo vi /etc/nginx/conf.d/default.conf. I can't find
  109.  
  110. ```server {
  111. listen 80;
  112. server_name localhost;
  113.  
  114. location / {
  115. root /usr/share/nginx/html;
  116. index index.html index.htm;
  117. }
  118. error_page 500 502 503 504 /50x.html;
  119. location = /50x.html {
  120. root /usr/share/nginx/html;
  121. }
  122.  
  123. }```
  124.  
  125. ..to make an edit. It just showing me as a blank. Here's the screencast
  126.  
  127. I sent a ticket to windows.nginx.apache.kvm.www.digitaloceandatacenters.info Support, they told me to force go on but I can't put this <?php phpinfo(); ?> in the file at** step five**.
  128.  
  129. Guys, help me!
  130. HeartedHeart
  131. 0
  132.  
  133. 0b7a770b9860b33000e31b870e815b33355f8459
  134. NearlyNormal September 5, 2015
  135.  
  136. I installed this way, and it only installed php 5.4. When I upgraded to php 5.6 with "yum install php56w-common"....etc, now Nginx and php-fpm are not linked to each other.
  137.  
  138. The default php56w* does not seem to install the php-fpm at this location:
  139. /var/run/php-fpm/php-fpm.sock
  140.  
  141. What should be the path? Do I need to change it in /etc/php-fpm.conf or something?
  142. HeartedHeart
  143. 0
  144.  
  145. 0b7a770b9860b33000e31b870e815b33355f8459
  146. NearlyNormal September 5, 2015
  147.  
  148. Any PHP from Nginx is giving me 502 bad gateway error.
  149.  
  150. My /etc/php-fpm.conf file has the following:
  151.  
  152. pid = /var/run/php-fpm/php-fpm.sock
  153.  
  154. Should I leave that as the default "pid = /var/run/php-fpm/php-fpm.pid" instead? What' the difference between sock and pid?
  155.  
  156. HeartedHeart
  157. 0
  158.  
  159. iamkingsleyf
  160. iamkingsleyf October 1, 2015
  161.  
  162. Thanks but how do I create virtual host for my wordpress sites?
  163. HeartedHeart
  164. 0
  165.  
  166. fixwen
  167. fixwen October 31, 2015
  168.  
  169. hello , i had some problems,
  170. I install the php5.6 but the nginx cannot work with it,how to config the php5.6 and make it work with nginx
  171.  
  172. centos7 + php5.6 + nginx
  173. HeartedHeart
  174. 0
  175.  
  176. djtthompson
  177. djtthompson November 9, 2015
  178.  
  179. Centos 7 users: http://stackoverflow.com/questions/23443398/nginx-error-connect-to-php5-fpm-sock-failed-13-permission-denied
  180. HeartedHeart
  181. 0
  182.  
  183. geo.sukarno
  184. geo.sukarno December 21, 2015
  185.  
  186. Thanks for you comprehensive tutorial.
  187. My web server is up and running, but cannot process the php script.
  188. Every time i open http://geosukarno.com/info.php , the info.php always served as download file.
  189.  
  190. You can see my Nginx's /etc/nginx/conf.d/default.conf at this txt file:
  191. http://geosukarno.com/nginx__default.conf.txt
  192.  
  193. I tried: systemctl restart nginx
  194. and: systemctl restart php-fpm
  195. didn't help.
  196.  
  197. Is somebody can help me, what i'm miss, that php script cannot be processed?
  198. HeartedHeart
  199. 0
  200.  
  201. geo.sukarno
  202. geo.sukarno December 22, 2015
  203.  
  204. I think i miss something.
  205. 8 hours until 6 hours ago, after i tried using SSL (http://www.server-world.info/en/note?os=CentOS_7&p=nginx&f=4), i tried some troubleshooting, such as restart the droplets, make sure the nginx's default.conf as same as tutorial's , still nginx cannot process the php script.
  206.  
  207. I always tried call info.php on https protocol (http://geosukarno.com/info.php), still nginx didn't process the php script.
  208. Now after 8 hour, i accidently call info.php on http protocol, and it's work. Nginx can process the php script.
  209. This 8 hours long, i didn't realize nginx already can process the php script, but on http protocol.
  210.  
  211. So, another problem still not solved yet.
  212. Why nginx cannot process php script when it called on https protocol?
  213. Every time i open http://geosukarno.com/info.php , the info.php always served as download file.
  214.  
  215. I made SSL certificate by following tutorial from server-world.info
  216. http://www.server-world.info/en/note?os=CentOS_7&p=nginx&f=4
  217.  
  218. HeartedHeart
  219. 0
  220.  
  221. geo.sukarno
  222. geo.sukarno December 22, 2015
  223.  
  224. Now i know why nginx didn't process php script on http protocol.
  225. Because at early time, in nginx's /etc/nginx/conf.d/default.conf , i'm using wrong servername.
  226. I was using servername gitu;
  227. gitu is my hostname.
  228. But my domain for this droplet is geosukarno.com
  229. Thats why nginx didn't process the php script on http protocol.
  230.  
  231. You can see my first Nginx's /etc/nginx/conf.d/default.conf that made nginx cannot process php script on http protocol at this txt file:
  232. http://geosukarno.com/nginx1default.conf.txt
  233. http://geosukarno.com/nginx1default.conf.txt
  234.  
  235. But until now, nginx still cannot process php script on https protocol.
  236.  
  237. HeartedHeart
  238. 0
  239.  
  240. geo.sukarno
  241. geo.sukarno December 22, 2015
  242. [deleted]
  243. HeartedHeart
  244. 0
  245.  
  246. geo.sukarno
  247. geo.sukarno December 22, 2015
  248.  
  249. I found why php script cannot be processed when called with https protocol on my nginx.
  250.  
  251. The mistake is,
  252. regarding to server-world.info's tutorial
  253. (http://www.server-world.info/en/note?os=CentOS_7&p=nginx&f=4)
  254. i put these 3 statements in /etc/nginx/nginx.conf
  255.  
  256. listen 443 ssl;
  257. ssl_certificate /etc/pki/tls/certs/server.crt;
  258. ssl_certificate_key /etc/pki/tls/certs/server.key;
  259.  
  260. Regarding to this tutorial, we using Nginx server block configuration file in
  261. /etc/nginx/conf.d/default.conf
  262.  
  263. Then i move those 3 statements from
  264. /etc/nginx/nginx.conf
  265. into
  266. /etc/nginx/conf.d/default.conf
  267.  
  268. You can see my Nginx server block configuration file
  269. /etc/nginx/conf.d/default.conf
  270. at
  271. http://geosukarno.com/nginx3default.conf.txt
  272.  
  273. Maybe you wondering what's another statements on my default.conf ?
  274. Well i got that configuration statements from chrismeller's tutorial:
  275. http://blog.chrismeller.com/configuring-and-optimizing-php-fpm-and-nginx-on-ubuntu-or-debian
  276.  
  277. Now my nginx can process php script on http and https protocol.
  278. HeartedHeart
  279. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement